package gp.app;

import genetic.GeneticProgram;
import genetic.treeelements.Function;
import genetic.treeelements.InputVariable;
import genetic.treeelements.Terminal;
import genetic.treeelements.functions.Addition;
import genetic.treeelements.functions.Division;
import genetic.treeelements.functions.Multiplication;
import genetic.treeelements.functions.Subtraction;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Random;

import jfchelper.XYSeriesFactory;

public class SerTest {

	public static void main(String[] args) {

        // setup function set
        ArrayList<Function> functionSet = new ArrayList<Function>();
        functionSet.add(new Addition());
        functionSet.add(new Subtraction());
        functionSet.add(new Multiplication());
        functionSet.add(new Division());

        // setup input-set and desired target-set
        ArrayList<InputVariable> inputSet = new ArrayList<InputVariable>();
        InputVariable x1 = new InputVariable("x1");
//        x1.setData(XYSeriesFactory.loadFromExcel("ABB.xls", "Last", 1));
//        inputSet.add(x1);

        // setup terminal-set
        ArrayList<Terminal> terminalSet = new ArrayList<Terminal>();
        Random rd = new Random();
        for (int i=0; i<2; i++) {
            terminalSet.add(new Terminal(rd.nextDouble()*5));
        }

        GeneticProgram gp = new GeneticProgram(functionSet, inputSet, terminalSet);
        gp.createRandom(10, 0);
        
        System.out.println(gp.toString());
        
	    try {
	        FileOutputStream fs = new FileOutputStream("alpa_eco.ser");
	        ObjectOutputStream os = new ObjectOutputStream(fs);
	        
	        os.writeObject(gp);
	        os.close();
	      } catch (IOException e) {
	        System.err.println(e.toString());
	      }
 	}

}
